﻿Public Class Service1
#Region "General"
    Protected Overrides Sub OnStart(ByVal args() As String)
        Try
            Timer1.Enabled = True
            Timer1.Interval = 6000 'Connection.iTime
            Timer1.Start()
        Catch ex As Exception
            SystemFunction.WriteLog(ex.ToString)
        End Try
    End Sub
    Protected Overrides Sub OnStop()
        Try
            Timer1.Enabled = False
            Timer1.Stop()
        Catch ex As Exception
            SystemFunction.WriteLog(ex.ToString)
        End Try
    End Sub
    Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
        Try
            Timer1.Enabled = False
            If PublicVariable.oCompanyInfo.Connected = False Then
                Dim objIniFile As New INIClass(Application.StartupPath + "\TOTALPOS.ini")
                Dim LicenserServer As String = objIniFile.GetString("SAP", "LicenserServer", "")
                Dim SQLServer As String = objIniFile.GetString("SAP", "SQLServer", "")
                Dim DBUser As String = objIniFile.GetString("SAP", "DBUser", "")
                Dim DBPwd As String = objIniFile.GetString("SAP", "DBPwd", "")
                Dim DBName As String = objIniFile.GetString("SAP", "DBName", "")
                Dim DBType As String = objIniFile.GetString("SAP", "DBType", "")
                Dim SAPUser As String = objIniFile.GetString("SAP", "SAPUser", "")
                Dim SAPPwd As String = objIniFile.GetString("SAP", "SAPPwd", "")
                Dim str As String = ""
                str = SAPFunctions.ConnectSAPDB(SQLServer, DBName, DBType, DBUser, DBPwd, SAPUser, SAPPwd, LicenserServer)
                If str <> "" Then
                    SystemFunction.WriteLog(str + "---------pls update setting then stop/start service.")
                    Timer1.Enabled = False
                    Return
                End If
            End If

            SAPFunctions.Syn_AllBill()

            Timer1.Enabled = True
        Catch ex As Exception
            SystemFunction.WriteLog(ex.ToString)
        End Try
    End Sub
#End Region
End Class
